import { ORDER_TYPE_UNPAID, ORDER_TYPE_PAID, ORDER_TYPE_SHIPPED,
    ORDER_TYPE_COMPLETED, ORDER_TYPE_CANCELED,
    ORDER_TYPE_CLOSED, ORDER_TYPE_AFTERMARKETING, CUSTOMER_TYPE_AUDIT, CUSTOMER_TYPE_AFTERMARKETING,
    CUSTOMER_TYPE_REJECTED, CUSTOMER_TYPE_AFTERMARKETED, CUSTOMER_TYPE_CLOSED } from '../../yali-sdk/business/order/constrants';
import config from '../config';
import { getIn } from '../../yali-sdk/utils/getIn';
const headColor = '#22b6ce';

/**
 * 更新参数集数据
 * @param params(可变数据)
 */
function updateVariableParams(params, data) {
    let mParams = {};
    if (data) {
      mParams = { ...params, ...data }
    }
    return mParams;
}
/** 列表底部文字 */
function getListFooterTitle(list) {
    let title = '';
    if (list && list.isLoading === true) {
        title = '正在加载中';
    } else if (list && list.isLoaded === true && !list.hasNext) {
        title = ' 已加载完成';
    }
    return title;
}
/** 弹出框 */
function showSuccess(title, duration, image) {
    const time = duration || 2000;
    wx.showToast({
        title,
        image,
        icon: 'success',
        time,
    });
}
function showFail(title, duration) {
    const time = duration || 2000;
    const image = '/image/ico_warning.png';
    wx.showToast({
        title,
        image,
        time,
    });
}

function getOrderStatusName(status) {
    let statusName = '';
    switch (Number(status)) {
        case ORDER_TYPE_UNPAID: {
            statusName = '未付款';
            break;
        }
        case ORDER_TYPE_PAID: {
            statusName = '已付款';
            break;
        }
        case ORDER_TYPE_SHIPPED: {
            statusName = '已发货';
            break;
        }
        case ORDER_TYPE_COMPLETED: {
            statusName = '已完成';
            break;
        }
        case ORDER_TYPE_CANCELED: {
            statusName = '已取消';
            break;
        }
        case ORDER_TYPE_CLOSED: {
            statusName = '已关闭';
            break;
        }
        case ORDER_TYPE_AFTERMARKETING: {
            statusName = '售后中';
            break;
        }
        default: break;
    }
    return statusName;
}

function getCustomerStatusName(status) {
    let customerStatusName = '';
    switch (Number(status)) {
        case CUSTOMER_TYPE_AUDIT: {
            customerStatusName = '审核中';
            break;
        }
        case CUSTOMER_TYPE_AFTERMARKETING: {
            customerStatusName = '售后中';
            break;
        }
        case CUSTOMER_TYPE_REJECTED: {
            customerStatusName = '已拒绝';
            break;
        }
        case CUSTOMER_TYPE_AFTERMARKETED: {
            customerStatusName = '售后完成';
            break;
        }
        case CUSTOMER_TYPE_CLOSED: {
            customerStatusName = '已关闭';
            break;
        }
        default: break;
    }
    return customerStatusName;
}
export const baseImagePath = () => global._yaliSetting && global._yaliSetting.qiniu_domain;

function getImagePath(path, useDefault = true) {
    if (typeof (path) === 'string' && path.length > 0) {
        if (path.indexOf('http:') !== -1 || path.indexOf('https:') !== -1) {
            // 如果是绝对路径，直接返回
            return path;
        }
        // 如果是相对的 拼接返回
        return baseImagePath() + path;
    }
    return '/image/defaultImg.jpg';
}

function uploadImage(imageUrlInPhone, folder, token, callback) {
    wx.uploadFile({
      url: 'https://www.nlido.com/upload/upload_file/upload_files',
        filePath: imageUrlInPhone,
        name: 'photo',
        formData: {
            photo: imageUrlInPhone, module: folder, lang_id: 1, token,
        },
        success(res) {
          const data = res.data;
          const photo = JSON.parse(data).data.photo;
          callback('SUCCESS', photo);
        },
        fail(res) {
            callback('FAIL', res);
        },
    });
    return true;
}
module.exports = {
    color: {
        headColor,
    },
    updateVariableParams,
    getListFooterTitle,
    showSuccess,
    showFail,
    getOrderStatusName,
    getCustomerStatusName,
    getImagePath,
    uploadImage,
};
